#pragma once

#include <SolarHashTable.h>
#include <Singleton.h>

struct MSG_BASE;
class ServerSession;

typedef util::SolarHashTable<ServerSession *>			SESSION_HASH;
typedef util::SolarHashTable<ServerSession *>::iterator	SESSION_HASH_ITR;

class ServerSessionManager : public util::Singleton<ServerSessionManager>
{
public:
	ServerSessionManager(void);
	virtual ~ServerSessionManager();

	ServerSession * AllocServerSession( eSERVER_TYPE eServerType );
	VOID FreeServerSession( ServerSession * pServerSession );

	VOID Process();
	inline ServerSession * FindServer( DWORD dwSessionIdx )					{ return m_SessionHash.GetData(dwSessionIdx); }
	inline VOID AddServer( ServerSession * pSession, DWORD dwSessionIdx )	{ m_SessionHash.Add( pSession, dwSessionIdx ); }
	inline VOID RemoveServer( DWORD dwSessionIdx )							{ m_SessionHash.Remove(dwSessionIdx); }

//	const SESSION_HASH & GetSessionHash() { return m_SessionHash; }

	VOID SendToServer( DWORD dwSessionIndex, MSG_BASE * pMsg, WORD wSize );
	VOID SendToAll( eSERVER_TYPE type, MSG_BASE * pMsg, WORD wSize );
	VOID SendToGameServerAll( MSG_BASE * pMsg, WORD wSize );
private:
	enum { _MAX_SESSION_BUCKET_SIZE = 30, };
	SESSION_HASH m_SessionHash;
};